package com.university.mentalhealthplatform.teacherV2.service;

import com.university.mentalhealthplatform.appModels.Tweet;
import com.university.mentalhealthplatform.teacherV2.repository.TweetRepositoryV2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TweetServiceV2 {
    @Autowired
    private TweetRepositoryV2 tweetRepositoryV2;

    public Tweet saveTweet(Tweet tweet) {
        return tweetRepositoryV2.save(tweet);
    }

    public List<Tweet> getAllTweets() {
        return tweetRepositoryV2.findAll();
    }

    public List<Tweet> getDrafts() {
        return tweetRepositoryV2.findByStatus("draft");
    }

    public List<Tweet> getTrash() {
        return tweetRepositoryV2.findByStatus("trash");
    }

    public Tweet getTweetById(Long id) {
        return tweetRepositoryV2.findById(id).orElse(null);
    }

    public void deleteTweet(Long id) {
        tweetRepositoryV2.deleteById(id);
    }

    public void moveToTrash(Long id) {
        Tweet tweet = tweetRepositoryV2.findById(id).orElseThrow(() -> new RuntimeException("Tweet not found"));
        tweet.setStatus("trash");
        tweetRepositoryV2.save(tweet);
    }
}